/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PictureID;

import elsimulatorjava.Person;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.AttributedString;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;

/**
 *
 * @author plitter
 */
public class PictureID extends JComponent {
    File file;
    BufferedImage picture;
    Person person;
    
    public PictureID(Person person) throws IOException {
        file = new File("images/elTexture2.jpg");
        picture = ImageIO.read(file);
        this.person = person;
        setPreferredSize(new Dimension (50,50));
        setSize(new Dimension(50,50));
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        // Just for text
        Graphics2D g2d = (Graphics2D) g;
        g.drawImage(picture, 0, 0, null);
        g.drawRect(0, 0, picture.getWidth(), picture.getHeight());
        
        // Settings for text
        Font font = new Font("Monospaced Plain", Font.PLAIN, 9);
        AttributedString as1;
        
        // Person ID
        String index = Integer.toString(person.getIndex());
        index = fixString(index, 4);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        as1 = new AttributedString(index);
        as1.addAttribute(TextAttribute.FONT, font);
        g2d.drawString(as1.getIterator(), 10, 50);
        
        // Person floorDestination
        String floorDestination = Integer.toString(person.getFloorDest());
        floorDestination = fixString(floorDestination, 2);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        as1 = new AttributedString(floorDestination);
        as1.addAttribute(TextAttribute.FONT, font);
        g2d.drawString(as1.getIterator(), 39, 10);
        
    }

    private String fixString(String index, int spaceNumber) {
        if (index.length() == spaceNumber) {
            return index;
        }
        return fixString(" "+index, spaceNumber);
    }
}
